<?php
$personal_folder = UPLOAD_FOLDER_URL. 'public/' . $shop->image_folder . '/';

$slide_img_path = $personal_folder . SHOP_SLIDE_IMAGE_URL;
$aSlideImage    = upload_modal_get($slide_img_path);

$banner_img_path = $personal_folder . SHOP_BANNER_IMAGE_URL;
$aBannerImage    = upload_modal_get($banner_img_path);

$temp_img_path = $personal_folder . TEMP_FOLDER_URL;
$aTempImage    = upload_modal_get($temp_img_path);

$uploaded_img_path = $personal_folder . 'uploaded/';
$aUploadedImage    = upload_modal_get($uploaded_img_path);
?>

<div id="modal-change-slide" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Slide</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="frm-upload-slide" method="post" action="<?php echo mns_page_url('hinh-anh/tai-len'); ?>" enctype="multipart/form-data">
                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-1 col-xs-6">
                            <input type="hidden" name="w_case" value="slide" />
                            <input type="hidden" name="w_case_folder" value="<?php echo $shop->image_folder; ?>" />
                            <input class="form-control" type="file" name="userfile" />
                        </div>
                        <div class="col-md-3 col-xs-5">
                            <button type="button" id="btn-confirm-slide" class="pull-left btn btn-success">
                                <i class="glyphicon glyphicon-ok-sign"></i>&nbsp;Xong&nbsp;
                            </button>
                        </div>
                    </div>
                </form>

                <div class="row thumbnail-list">
                    <div class="col-md-12">
                        <div id="slide-img-block" class="hidden ui-state-default">
                            <a class="fancybox" href="#">
                                <img src="" />
                            </a>
                            <p class="slide-status">
                                <input type="checkbox" class="chk-slide lb-toggle" name="setting_slide[]" checked='checked' />
                                <label class="lb-toggle-lb" for=''></label>
                            </p>
                        </div>
                        <p class="image-section"><i class="glyphicon glyphicon-chevron-right"></i> Đang được sử dụng</p>
                        <ul id="sortable">
                            <?php foreach($shop_slide as $index=>$objImg) { ?>
                                <li class="ui-state-default">
                                    <a class="fancybox" href="<?php echo slide_upload($objImg->image, $shop->image_folder, false); ?>">
                                        <img src="<?php echo slide_upload($objImg->image, $shop->image_folder); ?>" />
                                    </a>
                                    <p class="slide-status">
                                        <input id='chk-o-<?php echo $index+1; ?>' type="checkbox" class="chk-slide lb-toggle" name="setting_slide[]" value="<?php echo $objImg->image; ?>" checked='checked' data-value='<?php echo $objImg->image; ?>' />
                                        <label class="lb-toggle-lb" for='chk-o-<?php echo $index+1; ?>'></label>
                                    </p>
                                </li>
                            <?php } ?>

                            <?php foreach($aSlideImage as $index=>$img) { ?>
                                <?php
                                    $isUsed = false;
                                    foreach($shop_slide as $indexb=>$objImg) {
                                        if($objImg->image == $img) {
                                            $isUsed = true; break;
                                        }
                                    }
                                ?>
                                <?php if(!$isUsed) { ?>
                                    <li class="ui-state-default">
                                        <a class="fancybox" href="<?php echo slide_upload($img, $shop->image_folder, false); ?>">
                                            <img src="<?php echo slide_upload($img, $shop->image_folder); ?>" />
                                        </a>
                                        <p class="slide-status">
                                            <input id='chk-b-<?php echo $index+1; ?>' type="checkbox" class="chk-slide lb-toggle" name="setting_slide[]" value="<?php echo $img; ?>" data-value='<?php echo $img; ?>' />
                                            <label class="lb-toggle-lb" for='chk-b-<?php echo $index+1; ?>'></label>
                                        </p>
                                    </li>
                                <?php } ?>
                            <?php } ?>
                        </ul>
                        <p class="image-section"><i class="glyphicon glyphicon-chevron-right"></i> Đã tải lên</p>
                        <ul id="image-temp-upload" class="image-list clearPad">
                            <?php foreach($aUploadedImage as $img) { ?>
                            <li>
                                <a href="<?php echo upload_raw($img, $shop->image_folder); ?>" class="li-temp thumbnail img-block-edit slide-img-block" data-url-remove="<?php echo admin_page_url('hinh-anh/xoa'); ?>" data-folder='<?php echo 'uploaded/'; ?>' data-name='<?php echo $img; ?>'>
                                    <img class="media-object" src="<?php echo upload_raw($img, $shop->image_folder); ?>" />
                                </a>
                            </li>
                            <?php } ?>
                        </ul>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>

<div id="modal-change-banner" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Banner</h4>
            </div>
            <div class="modal-body">
                <div class="image-current">
                    <div class="row">
                        <div class="col-md-12 col-xs-12">
                            <form role="form" id="frm-upload-banner" method="post" action="<?php echo mns_page_url('hinh-anh/tai-len'); ?>" enctype="multipart/form-data">
                                <div class="form-group col-md-6 col-md-offset-2 cpl-xs-6">
                                    <input class="form-control" type="file" name="userfile" />
                                </div>
                                <div class="form-group col-md-1 col-xs-2">
                                    <button id="btn-change-img" class="btn btn-primary">
                                        Tải lên
                                        <span class="percent hidden">0%</span>
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                    <p class="image-section"><i class="glyphicon glyphicon-chevron-right"></i> Đang được sử dụng</p>
                    <ul class="image-list clearPad">
                        <?php foreach($aBannerImage as $img) { ?>
                        <li>
                            <a href="<?php echo banner_upload($img, $shop->image_folder); ?>" class="thumbnail img-block-edit banner-img-block" data-url-remove="<?php echo admin_page_url('hinh-anh/xoa'); ?>" data-folder='<?php echo SHOP_BANNER_IMAGE_URL; ?>' data-name='<?php echo $img; ?>'>
                                <img class="media-object" src="<?php echo banner_upload($img, $shop->image_folder); ?>" />
                            </a>
                        </li>
                        <?php } ?>
                    </ul>
                    <ul class="image-list clearPad">
                        <li class="hidden" id="banner-img-block">
                            <a class="li-temp thumbnail img-block-edit banner-img-block" data-url-remove="<?php echo admin_page_url('hinh-anh/xoa'); ?>" data-folder='<?php echo TEMP_FOLDER_URL; ?>' data-name=''>
                                <img class="media-object" />
                            </a>
                        </li>
                    </ul>
                    <p class="image-section"><i class="glyphicon glyphicon-chevron-right"></i> Đã tải lên</p>
                    <ul id="image-temp-upload" class="image-list clearPad">
                        <?php foreach($aTempImage as $img) { ?>
                        <li>
                            <a href="<?php echo temp_image($img, $shop->image_folder); ?>" class="li-temp thumbnail img-block-edit banner-img-block" data-url-remove="<?php echo admin_page_url('hinh-anh/xoa'); ?>" data-folder='<?php echo TEMP_FOLDER_URL; ?>' data-name='<?php echo $img; ?>'>
                                <img class="media-object" src="<?php echo temp_image($img, $shop->image_folder, true); ?>" />
                            </a>
                        </li>
                        <?php } ?>
                    </ul>
                </div>
                <div class="clearfix"></div>
                <div class="image-resize hidden">
                    <form id="frm-crop" method="POST" action="<?php echo admin_page_url('hinh-anh/crop'); ?>">
                        <div id="img-wrap" data-thumb-width="<?php echo BANNER_THUMB_W; ?>" data-screen-width="300">
                            <img src="" id="crop-target" data-ratio="<?php echo BANNER_THUMB_RATIO; ?>" />
                        </div>
                        <div class="inline-labels hidden">
                            <label>X1 <input type="hidden" size="4" id="x1" name="crop[x1]" /></label>
                            <label>Y1 <input type="hidden" size="4" id="y1" name="crop[y1]" /></label>
                            <label>X2 <input type="hidden" size="4" id="x2" name="crop[x2]" /></label>
                            <label>Y2 <input type="hidden" size="4" id="y2" name="crop[y2]" /></label>
                            <label>W  <input type="hidden" size="4" id="w"  name="crop[w]" /></label>
                            <label>H  <input type="hidden" size="4" id="h"  name="crop[h]" /></label>
                        </div>
                        <br />
                        <input type="hidden" id="input-crop-path" name="crop[path]" value=""/>
                        <input type="hidden" name="crop[w_case]" value="<?php echo SHOP_BANNER_IMAGE_URL; ?>"/>
                        <button id="btn-crop" type="button" class="btn btn-success" name="submit">Cắt Hình</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="modal-preview-theme" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Gian hàng mẫu</h4>
            </div>
            <div class="modal-body">
                <?php
                $dirs = scandir(APPPATH.'/views/shop-themes');
                $need_dirs = array();
                foreach($dirs as $d){
                    if($d!='.' && $d!='..' && $d!='index.html'){ array_push($need_dirs, $d);}
                }
                $dirs = $need_dirs;
                ?>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12 mgbt10">
                        <button id="btn-choose-theme" type="button" class="btn btn-success pull-right" data-value="<?php echo $shop->template; ?>">
                            <i class="glyphicon glyphicon-ok-sign"></i> Xong
                        </button>
                    </div>
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <ul id="preview-theme">
                            <?php foreach ($dirs as $key => $theme) { ?>
                            <li>
                                <a class="theme-img <?php echo $theme==$shop->template?'thumbnail-selected':''; ?>" href="#" title="<?php echo $theme; ?>" data-theme="<?php echo $theme; ?>">
                                    <img src="<?php echo shop_assets_preview($theme); ?>"/>
                                    <p class="caption"><?php echo $theme; ?></p>
                                </a>
                                <p class="btn-preview">
                                    <a target="_blank" class="btn btn-primary" href="<?php echo shop_url($shop->slug) ; ?>?m=preview&amp;t=<?php echo $theme; ?>" title="<?php echo $theme; ?>"><i class="glyphicon glyphicon-picture"></i> Xem</a>
                                </p>
                            </li>
                            <?php } ?>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>